#!/bin/bash
#set -n
#xslt=$ii/misc/trunk/emr_loader/src/java/CDSProdtoODS.xsl
xslt=$ii/misc/trunk/testsearchn/src/xsl/CDSProdtoODSk.xsl
xslt=$ii/misc/trunk/testsearchn/src/xsl/CDSProdtoODSk2.xsl
#xslt=$ii/misc/trunk/testsearchn/src/xsl/CDSProdtoODSu.xsl
for jar in /mo*/gn*/ap*/*lan*/*0/*jar ; do
	export CLASSPATH="$CLASSPATH;$jar"
done
echo "CLASSPATH=$CLASSPATH"
function transtoxml {
	pfn=$1
	rfile="${pfn%%.cpf.xml}"
	docid="$(basename $rfile)"
	nfn="$rfile.xml"
	echo "$docid,$pfn,$nfn"
	if [[ 1 || (! -f $nfn) ]] ; then
		java org.apache.xalan.xslt.Process -in $pfn \
			-xsl $xslt | \
			sed -e \
			"s#<original_docid></original_docid>#<original_docid>$docid</original_docid>#g" \
			> $nfn
	else
		echo "$nfn exists skipping."
	fi
}
fn="$1"
if [[ -z "$fn" ]] ; then
	find . -name '*.cpf.xml' -exec $0 {} \;
else
	if [[ ! -f $xslt ]] ; then
		echo "Could not find $xslt"
		exit 1
	fi
	transtoxml $fn
fi
